package com.atom.app.mvi.ui.compose.view.text_icon

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.atom.app.mvi.R

class TextIconScope {

}

@Preview
@Composable
fun testPre() {
    TextIcon(
        modifier = Modifier.size(100.dp),
        icon = painterResource(id = R.mipmap.icon_launcher),
        title = "asdasd",
        textColor = Color.Green
    ) {

    }
}

@Composable
fun TextIcon(
    modifier: Modifier = Modifier,
    icon: Painter,
    title: String,
    iconContentDescription: String = "",
    weight: Float = 0.618f,
    textColor: Color = Color.Black,
    textSize: TextUnit = TextUnit.Unspecified,
    onClick: () -> Unit
) {
    Column(
        modifier = modifier.clickable(onClick = onClick), verticalArrangement = Arrangement.Center
    ) {
        Icon(
            painter = icon,
            contentDescription = iconContentDescription,
            tint = Color.Unspecified,
            modifier = Modifier
                .weight(weight)
                .fillMaxWidth()
        )
        Text(
            text = title,
            modifier = Modifier
                .weight(1 - weight)
                .fillMaxWidth()
                .wrapContentSize(align = Alignment.Center),
            maxLines = 1,
            color = textColor,
            fontSize = textSize
        )
    }
}